#include <func.h>

int main(int argc,char *argv[])
{
    int fds[2];
    pipe(fds);
    if(!fork())
    {
        close(fds[1]);
        int childfd;
        char buf[20]={0};
        read(fds[0],&childfd,sizeof(int));
        printf("fds[0]=%d\n",fds[0]);
        printf("childfd=%d\n",childfd);
        read(childfd,buf,sizeof(buf));
        printf("I am child,%s\n",buf);
    }
    else{
        close(fds[0]);
        int fd=open("file",O_RDONLY);
        write(fds[1],&fd,sizeof(int));
        wait(NULL);
    }
    return 0;
}

